/** Author: David Powell
This file produces Figure A5
**/


clear all
set more off

global dir "/jules/b/dpowell"
global DATA "${dir}/purdue/replication/DATA"
global OUTPUT "${dir}/purdue/replication/output"



use ${DATA}/finaldata


**create outcomes and annualize
gen mc_oxycontin=1000*oxycontin_SDUD/medicaidb
replace mc_oxycontin=mc_oxycontin*4/numobs

gen mc_oxycodone=1000*oxycodone_SDUD/medicaidb
replace mc_oxycodone=mc_oxycodone*4/numobs

set scheme s2color  

keep if year<2006


***EVENT STUDY****
foreach nnn of numlist 1991/2005 {
	gen tt_`nnn'=nontripl*(year==`nnn')
}
drop tt_1995
keep if year>1990
tab stf, gen(ss) nof
tab year, gen(yy) nof



**create balanced panel
egen missing=max(other==.), by(stf)
drop if missing>0

gen beta1=0
gen low1=0
gen high1=0
gen other=mc_oxycodone-mc_oxycontin

sort stf year
reg other ss* yy* tt_* [aw=medicaidbene]  , cluster(stf)

foreach nnn2 of numlist 1991/1994 1996/2005 {
	replace beta1=_b[tt_`nnn2'] if year==`nnn2'
	boottest tt_`nnn2', boottype(wild) weighttype(webb) reps(9999) seed(23857389)
	matrix A=r(CI)
	replace low1=A[1,1] if year==`nnn2'
	replace high1=A[1,2] if year==`nnn2'		
}



bys year: keep if _n==1


# delimit ;

twoway(rarea low1 high1 year if year>1990 & year<2006 & year!=1995, color(gs14))  (connected beta1 year if year>1990 & year<2006, color(black) msize(vtiny) sort yaxis(1)) 
, graphregion(color(white)) ylabel(,nogrid) yline(0, lpattern(dash) lcolor(gs6))  xlabel(1991(1)2005 , angle(45))   legend(label(2 "Estimate") label(1 "95% Confidence Interval")  rows(1) order(2 1)) xtitle("Year") ytitle("Oxycodone Prescriptions (Excluding OxyContin)" "per 1,000 Beneficiaries"  ,  axis(1));
gr export ${OUTPUT}/figA5.eps, replace;





